package com.javaee.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;

/**
 * 跨域
 * 
 * @author LYL
 * @version 2017年3月16日-上午10:55:26
 */
@WebFilter(urlPatterns={"/*"},description="支持跨域")
public class BasicFilter implements Filter {

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterchain)
			throws IOException, ServletException {
		HttpServletResponse response = (HttpServletResponse) servletResponse;
		// 指定允许其他域名访问
		response.addHeader("Access-Control-Allow-Origin", "*");
		// 响应类型 响应方法
		response.addHeader("Access-Control-Allow-Headers", "Authentication");
		response.addHeader("Access-Control-Max-Age", "30");
		response.addHeader("Access-Control-Allow-Credentials", "true");
		filterchain.doFilter(servletRequest, servletResponse);
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
